package model;


import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;

import db.Kunde;


public class KundenModel  {
    
    private List<Kunde> kundeList = new ArrayList<Kunde>();
	protected transient PropertyChangeSupport listeners = new PropertyChangeSupport(this);
    
    
    
    /**
     * Adds a property-change listener.
     * @param l the listener
     */
    public void addPropertyChangeListener(PropertyChangeListener l){
        if (l == null) {
            throw new IllegalArgumentException();
        }
        this.listeners.addPropertyChangeListener(l);
    }
    
    
    public void removePropertyChangeListener(PropertyChangeListener l){
        this.listeners.removePropertyChangeListener(l);
    }
    
    /**
     * Notificates all listeners to a model-change
     * @param prop the property-id
     * @param old the old-value
     * @param newValue the new value
     */
    protected void firePropertyChange(String prop, Object old, Object newValue){
        if (this.listeners.hasListeners(prop)) {
            this.listeners.firePropertyChange(prop, old, newValue);
        }
    }

    public void addKunde(Kunde o) {
        this.kundeList.add(o);
        // model has changed --> fire
        firePropertyChange("KUNDE_ADD", null, o); //$NON-NLS-1$
    }
    
    public void remove(Kunde o) {
        this.kundeList.remove(o);
//      model has changed --> fire
        firePropertyChange("KUNDE_REMOVE", o, null); //$NON-NLS-1$
    }
    
    public List<Kunde> getKundeList() {
		return new ArrayList<Kunde>(kundeList);
	}


}
